﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NhaCungCap.DTO;
using System.Data.OleDb;
using System.Text;
using System.Data;

namespace NhaCungCap.DAO
{
    public class LoaiUserDAO
    {
        public static List<LoaiUserDTO> Select()
        {
            List<LoaiUserDTO> listUT = new List<LoaiUserDTO>();
            DataProvider provider = new DataProvider();
            try
            {
                string query = "SELECT * FROM UserType";
                DataTable datatable = provider.ExecuteQuery(query);

                for (int i = 0; i < datatable.Rows.Count; ++i)
                {
                    LoaiUserDTO UT = new LoaiUserDTO();

                    UT.IdLoaiUser = Convert.ToInt32(datatable.Rows[i]["ID"]);
                    UT.TenLoaiUser = Convert.ToString(datatable.Rows[i]["Name"]);
                    UT.PhanQuyen = Convert.ToString(datatable.Rows[i]["UserRight"]);

                    listUT.Add(UT);
                }
            }
            catch (Exception ex)
            {
                listUT = new List<LoaiUserDTO>();
            }
            finally
            {
                provider.Disconnect();
            }
            return listUT;
        }

        public static bool Insert(LoaiUserDTO US)
        {
            DataProvider provider = new DataProvider();
            bool kq = true;
            try
            {
                string query = "INSERT INTO LoaiUser( TenLoaiUser, PhanQuyen) VALUES(" + US.TenLoaiUser + ", " + US.PhanQuyen + ")";
                kq = provider.ExecuteNonQuery(query);
            }
            catch (Exception ex)
            {
                kq = false;
            }
            finally
            {
                provider.Disconnect();
            }

            return kq;
        }
    }
}